<div id='panel'>

<?php
mysql_query("update tbl_messages set status='2'  where messageid='".$_GET['read']."'");
  $sqlMsg="select *,Now() as current_date1,DATE_ADD(bargain_accept_date,INTERVAL 2 DAY) as Expire_date from tbl_messages where messageid='".$_GET['read']."'";
  $resMsg=mysql_query($sqlMsg);
  $rowMsg=mysql_fetch_array($resMsg);
	if($rowMsg['type']=="Payment")
	{
		$algn='align=center';
		$current_date=$rowMsg['current_date1'];
		$payment_date=$rowMsg['bargain_accept_date'];
		$Expire_date=$rowMsg['Expire_date'];
	}
	
	function timeRemain($start_date,$end_date)
	{
	  $start = strtotime($start_date);
	  $end = strtotime($end_date);
	  $remain=$start-$end;	 
	  $str=""; 
	  if((int)$remain>0)
	  {
	  	echo sec2hms($remain,false);
		
	  }
	}
	function sec2hms($sec, $padHours = false) {

    $hms = "";
    
    // there are 3600 seconds in an hour, so if we
    // divide total seconds by 3600 and throw away
    // the remainder, we've got the number of hours
    $hours = intval(intval($sec) / 3600); 

    // add to $hms, with a leading 0 if asked for
    $hms .= ($padHours) 
          ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
          : $hours. ':';
     
    // dividing the total seconds by 60 will give us
    // the number of minutes, but we're interested in 
    // minutes past the hour: to get that, we need to 
    // divide by 60 again and keep the remainder
    $minutes = intval(($sec / 60) % 60); 

    // then add to $hms (with a leading 0 if needed)
    $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';

    // seconds are simple - just divide the total
    // seconds by 60 and keep the remainder
    $seconds = intval($sec % 60); 

    // add to $hms, again with a leading 0 if needed
    $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);

    return $hms;
}
	
	function greaterDate($start_date,$end_date)
	{
	  $start = strtotime($start_date);
	  $end = strtotime($end_date);
	  if ($start-$end > 0)
		return 1;
	  else
	   return 0;
	}
  ?>
  <script language="javascript1.2">
function pay_now(objvalue)
{
	//alert(objvalue);
	location.href="amazon_pay.php?msg="+objvalue;
}

</script>
<table width="100%" border="0" cellpadding="5">
 
<tr>
<td>  
<div class="fulldiv">
	<div class="greytab_out" style="float:left; margin:10px 5px -8px 14px;">
		<div class="greytab_left">&nbsp;</div>
		<div class="greytab_repeat">Delete</div>
		<div class="greytab_right">&nbsp;</div>
	</div>&nbsp;&nbsp;
	<div class="greytab_out" style="float:left; margin:10px 5px -8px 10px;">
		<a href="index.php?reply=<?php echo $rowMsg['messageid'];?>">
		<div class="greytab_left">&nbsp;</div>
		<div class="greytab_repeat">Reply</div>
		<div class="greytab_right">&nbsp;</div></a>
	</div>&nbsp;&nbsp;
	<div class="greytab_out" style="float:left; margin:10px 5px -8px 10px;">
		<a href="index.php?inbox"><div class="greytab_left">&nbsp;</div>
		<div class="greytab_repeat">My Inbox</div>
		<div class="greytab_right">&nbsp;</div></a>
	</div>
</div>


<div class="fulldiv">
<div class="fullbox2_top">&nbsp;</div>
<div class="fullbox2_repeat">

<div class="fdbk_box"> 	
	<table width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td width="76%"><strong><?php echo $rowMsg['subject'];?></strong></td>
			<td align="right" nowrap="nowrap"><?php echo $rowMsg['posteddate'];?> </td>
			<td align="right" nowrap="nowrap"></td>
		</tr>
		
		  
  <tr>
    <td colspan="3" <?php echo $algn;?>>
	
	<?php echo $rowMsg['message']."<br/>";
	if($rowMsg['type']=="accept")
	{
		$current_date=$rowMsg['current_date1'];
		$payment_date=$rowMsg['bargain_accept_date'];
		$Expire_date=$rowMsg['Expire_date'];
		//bargain_accept_date
		//$today=today();
		//echo strtotime($today);
		//echo date('Y-m-d H:i:s');
		//echo $current_date;
		
		//$date1='2007-10-10 12:15:27';
		//$date2='2007-10-10 11:17:37';
		//echo $current_date."<br/>";
		//echo $Expire_date;		
		if($rowMsg['is_buyed']==0)
			if(greaterDate($Expire_date,$current_date))
			{
				$msg_id=$rowMsg['messageid'];
				echo "<br/>";
				timeRemain($Expire_date,$current_date);
				echo "<br/><br/> <input type='button' value='Pay' onclick='return pay_now($msg_id);' />";
			}
		//else
//		{
//			echo "expire";
//		}
		   
		
		   
	}	
	if($algn!="")
	{
		//bargain_accept_date
		//$today=today();
		//echo strtotime($today);
		//echo date('Y-m-d H:i:s');
		//echo $current_date;
		
		//$date1='2007-10-10 12:15:27';
		//$date2='2007-10-10 11:17:37';
		//echo $current_date."<br/>";
		//echo $Expire_date;		
		if($rowMsg['is_buyed']==0)
			if(greaterDate($Expire_date,$current_date))
			{
				$msg_id=$rowMsg['messageid'];
				echo "<br/>";
				timeRemain($Expire_date,$current_date);
				echo "<br/><br/> <input type='button' value='Pay' onclick='return pay_now($msg_id);' />";
			}
		//else
//		{
//			echo "expire";
//		}
		   
		
		   
	}	
	?>
	
	</td>
    </tr>
	<?php
	 
	$sqlOwner="select * from tbl_product where product_id='".$rowMsg['productid']."'";
	$resOwner=mysql_query($sqlOwner);
	$rowOwner=mysql_fetch_array($resOwner);
	$ownerid=$rowOwner['posted_by'];
	if($rowMsg['section']=="W")
	{
	$ownerid=$rowMsg['recieverid'];
	}
	if($rowMsg['section']=="C")
	{
	$ownerid=$rowMsg['recieverid'];
	}
	if($rowMsg['section']=="WS")
	{
	$ownerid=$rowMsg['recieverid'];
	}
	if($rowMsg['section']=="WSS")
	{
	$ownerid=$rowMsg['recieverid'];
	}
	
	if($rowMsg['type']=="Bargain" && $ownerid==$rowMsg['recieverid']) {?>
  <tr>
    <td colspan="3"><a href="index.php?reply=<?php echo $rowMsg['messageid'];?>&amp;type=bargain&amp;action=accept">Accept</a> | <a href="index.php?reply=<?php echo $rowMsg['messageid'];?>&amp;type=bargain&amp;action=decline">Decline</a> | <a href="index.php?reply=<?php echo $rowMsg['messageid'];?>&amp;type=bargain&amp;action=counter">Counter Offer</a> </td>
  </tr>
  <?php }?>
	</table>

</div>

</div>
<div class="fullbox2_bot">&nbsp;</div>
</div>
</td>
</tr>
  
  

</table>
</div>
<br>